<template>
  <div>
    <div class="dizhi">
      <ul>
        <li>
          <div class="left">
            <p class="ziliao">
              <span class="name">{{ dizhi.name }}</span>
              <span class="dianhua">{{ dizhi.tel }}</span>
              <span class="moren">默认</span>
            </p>
            <p class="dizhi">{{ dizhi.province + dizhi.addressDetail }}</p>
          </div>
          <div
            class="right"
            @click="
              $router.push({
                name: 'addshouhuodizhi',
                query: {
                  dingdandizhi: dizhi,
                  time: list[0].time,
                },
              })
            "
          >
            >
          </div>
        </li>
      </ul>
      <div class="xian"></div>
    </div>
    <!-- 商品列表 -->
    <ul class="b4">
      <li v-for="item in list" :key="item.cartid">
        <div class="img"><img :src="item.img1" alt="" /></div>
        <div class="text">
          <h5>{{ item.proname }}</h5>
          <p class="p1">
            <span class="jiage">¥{{ item.originprice }}</span>
            <span class="jishuqi"> 数量: {{ item.num }} </span>
          </p>
          <p class="p2">
            商品总价:
            <span style="color: orange">{{ item.num * item.originprice }}</span>
          </p>
        </div>
      </li>
    </ul>
    <!-- 合计 -->
    <div class="heji">共计:¥{{ heji }}</div>
    <div class="buttom">
      <p>
        <span>实付: </span><span>¥ {{ heji }}</span>
      </p>
      <button @click="ok">立即购买</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dizhi: {},
      list: [],
    };
  },
  mounted() {
    this.get();
    this.$emit("fanhui", 6);
  },
  methods: {
    get() {
      //获取订单信息
      let params = {
        userid: sessionStorage.getItem("userid"),
        time: this.$route.query.time,
      };
      axios
        .get("http://121.89.205.189:3000/api/order/confirmOrder", {
          headers: { token: sessionStorage.getItem("token") },
          params,
        })
        .then((res) => {
          this.dizhi = res.data.address;
          this.list = res.data.data;
        });
    },
    ok() {
      let userid = sessionStorage.getItem("userid");
      axios
        .get(
          `http://121.89.205.189:3000/api/order/deleteCartItem?userid=${userid}`,
          {
            headers: { token: sessionStorage.getItem("token") },
          }
        )
        .then((res) => {
          this.$route.fullPath;
        });
    },
  },
  computed: {
    heji() {
      let num = 0;
      this.list.forEach((item) => {
        num += item.num * item.originprice;
      });
      return num;
    },
  },
};
</script>

<style lang="less" scoped>
.dizhi {
  width: 100%;
  height: 1.1rem;
}
.dizhi {
  display: flex;
  flex-direction: column;
  > ul {
    width: 100%;
    display: flex;
    flex-direction: column;
    > li {
      width: 100%;
      height: 1rem;
      background: white;
      display: flex;
      justify-content: space-between;
      > .left {
        display: flex;
        flex-direction: column;
        justify-content: center;

        > .ziliao {
          display: flex;
          padding: 0.1rem;
          > .name,
          .dianhua {
            font-size: 0.15rem;
            font-weight: 700;
            margin-right: 0.1rem;
          }

          > .moren {
            background: red;
            color: white;
            margin-left: 0.05rem;
            padding: 0 0.05rem;
            border-radius: 0.1rem;
          }
          > .jia {
            background: blue;
            color: white;
            margin-left: 0.05rem;
            padding: 0 0.05rem;
            border-radius: 0.05rem;
          }
        }
        > .dizhi {
          color: #999999;
          font-size: 0.1rem;
          padding: 0.1rem;
        }
      }
      .right {
        display: flex;
        justify-content: center;
        align-items: center;
        > div {
          padding: 0.1rem;
        }
      }
    }
  }
}
.xian {
  width: 100%;
  height: 0.05rem;
  background: repeating-linear-gradient(
    -45deg,
    #fb6547,
    #fb6547 20%,
    transparent 0,
    transparent 25%,
    #78a9ff 0,
    #78a9ff 45%,
    transparent 0,
    transparent 50%
  );
  background-size: 100px;
}
.b4 {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  > li {
    width: 100%;
    height: 1.57rem;
    border-bottom: 1px solid #ccc;
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    > .check {
      width: 0.45rem;
      display: flex;
      justify-content: center;
      align-items: center;
      > input {
        width: 0.2rem;
        height: 0.2rem;
      }
    }
    .img {
      width: 0.9rem;
      display: flex;
      justify-content: center;
      align-items: center;
      > img {
        width: 0.9rem;
        height: 0.9rem;
      }
    }
    .text {
      width: 2rem;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 0 0.15rem;
      > h5 {
        width: 100%;
        height: 0.7rem;
      }
      .p2 {
        width: 100%;
        display: flex;
        margin-top: 0.3rem;
      }
      > .p1 {
        width: 100%;
        display: flex;
        justify-content: space-between;
        > .jiage {
          width: 0.3rem;
          color: red;
        }
        > .jishuqi {
          width: 0.87rem;
          height: 0.22rem;
          display: flex;
          > input {
            width: 0.4rem;
            border-top: 1px solid rgb(222, 219, 219);
            border-bottom: 1px solid rgb(222, 219, 219);
            border-left: 0 solid rgb(222, 219, 219);
            border-right: 0 solid rgb(222, 219, 219);
            text-align: center;
            color: rgb(106, 106, 106);
          }
          > button {
            width: 0.22rem;
            border: none;
            border: 1px solid rgb(222, 219, 219);
            background: white;
            color: rgb(222, 219, 219);
          }
        }
      }
    }
  }
}
.heji {
  height: 0.4rem;
  background: white;
  text-align: right;
  padding-right: 0.15rem;
  line-height: 0.4rem;
}
.buttom {
  width: 100%;
  height: 0.44rem;
  background: white;
  position: fixed;
  bottom: 55px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  button {
    width: 0.84rem;
    height: 0.3rem;
    border-radius: 0.55rem;
    background-image: linear-gradient(90deg, #ff9000 0%, #ff5000 98%);
    font-size: 15px;
    color: white;
    border: none;
    margin-right: 0.15rem;
  }
  > p {
    display: flex;
    margin-left: 0.15rem;

    > :nth-child(1) {
      font-size: 0.16rem;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    > :nth-child(2) {
      font-size: 0.2rem;
      color: orange;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>